import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt

#
# I'm breaking this down into needless levels of widgetry
#
# sometimes it just helps me think about it
#

class TimePanelCell(QtGui.QWidget):
	def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)

		bg = QtGui.QLabel(self)
		path = "resources/time_panel_cell.png"
		bg.setPixmap(QtGui.QPixmap(path))
		bg.setGeometry(0,0,16,18)

		font = QtGui.QFont("Times New Roman", 14)
		text = QtGui.QLabel(self)
		text.setPixmap(QtGui.QPixmap(path))
		text.setGeometry(1,0,16,18)
		text.setFont(font)
		text.setAlignment(Qt.AlignVCenter|Qt.AlignHCenter)
		self.text = text

	def set_text(self, s):
		self.text.setText(s)

	def set_num(self, ival):
		self.text.setText("{}".format(ival))
		

class TimePanel2Box(QtGui.QWidget):
	def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)

		bg = QtGui.QLabel(self)
		path = "resources/time_panel_2cell.png"
		bg.setPixmap(QtGui.QPixmap(path))
		bg.setGeometry(0,0,69,21)

		self.d1 = TimePanelCell(self)
		self.d1.move(1,1)

		self.d0 = TimePanelCell(self)
		self.d0.move(17,1)

	def set_digits(self, ival):

		s = "{0:02d}".format(ival)
		l = list(s)

		self.d1.set_text(l[0])
		self.d0.set_text(l[1])

class TimePanel4Box(QtGui.QWidget):
	def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)

		bg = QtGui.QLabel(self)
		path = "resources/time_panel_4cell.png"
		bg.setPixmap(QtGui.QPixmap(path))
		bg.setGeometry(0,0,69,21)

		self.d3 = TimePanelCell(self)
		self.d3.move(1,1)

		self.d2 = TimePanelCell(self)
		self.d2.move(17,1)

		self.d1 = TimePanelCell(self)
		self.d1.move(34,1)

		self.d0 = TimePanelCell(self)
		self.d0.move(50,1)

	def set_digits(self, ival):

		s = "{0:04d}".format(ival)
		l = list(s)

		self.d3.set_text(l[0])
		self.d2.set_text(l[1])
		self.d1.set_text(l[2])
		self.d0.set_text(l[3])

class TimePanel_Time(QtGui.QWidget):
	def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)

		bg = QtGui.QLabel(self)
		path = "resources/time_panel_time_label.png"
		bg.setPixmap(QtGui.QPixmap(path))
		bg.move(8,0)

		self.time = TimePanel4Box(self)
		self.time.move(0, 16)

	def set_time(self, time):
		self.time.set_digits(time)

class TimePanel_Day(QtGui.QWidget):
	def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)

		bg = QtGui.QLabel(self)
		path = "resources/time_panel_day_label.png"
		bg.setPixmap(QtGui.QPixmap(path))
		bg.move(12,0)

		self.day = TimePanel4Box(self)
		self.day.move(0, 16)

	def set_day(self, day):
		self.day.set_digits(day)



class TimePanel_Date(QtGui.QWidget):
	def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)

		bg = QtGui.QLabel(self)
		path = "resources/time_panel_date_label.png"
		bg.setPixmap(QtGui.QPixmap(path))
		bg.move(44,0)

		self.yyyy = TimePanel4Box(self)
		self.yyyy.move(0, 16)

		self.mm = TimePanel2Box(self)
		self.mm.move(70, 16)

		self.dd = TimePanel2Box(self)
		self.dd.move(108, 16)

	def set_date(self, dd, mm, yyyy):
		self.yyyy.set_digits(yyyy)
		self.dd.set_digits(dd)
		self.mm.set_digits(mm)

class TimePanel_BG(QtGui.QWidget):
	def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)

		bg = QtGui.QLabel(self)
		path = "resources/time_panel_bg.png"
		bg.setPixmap(QtGui.QPixmap(path))
		bg.setGeometry(0,0,349,52)

class TimePanel(QtGui.QWidget):
	def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)
		self.setGeometry(0,0,349,52)

		bg = TimePanel_BG(self)
		self.date = TimePanel_Date(self)
		self.date.move(17, 9)
		self.day = TimePanel_Day(self)
		self.day.move(176, 9)
		self.time = TimePanel_Time(self)
		self.time.move(259, 9)

	def set_date(self, dd, mm, yyyy):
		self.date.set_date(dd, mm, yyyy)

	def set_day(self, day):
		self.day.set_day(day)

	def set_time(self, time):
		self.time.set_time(time)

if __name__ == "__main__":

	app = QtGui.QApplication(sys.argv)


	top = QtGui.QLabel()
	path = "resources/wood.jpg"
	top.setPixmap(QtGui.QPixmap(path))
	top.setGeometry(0,0,1024,768)

	box = TimePanel4Box(top)
	box.set_digits(1234)
	box.move(20,20)

	box2 = TimePanel2Box(top)
	box2.set_digits(56)
	box2.move(20,50)

	date = TimePanel_Date(top)
	date.set_date(1,1,1234)
	date.move(20,80)

	date = TimePanel_Day(top)
	date.set_day(4)
	date.move(20, 130)

	time = TimePanel_Time(top)
	time.set_time(1439)
	time.move(20, 180)

	panel = TimePanel_BG(top)
	panel.move(20, 230)

	total = TimePanel(top)
	total.move(20, 300)
	total.set_date(11,12,2013)
	total.set_time(2134)
	total.set_day(43)

	top.show()
	app.exec_()
